<template>
  <div class="login">
    <div class="login_start">
      <h2>用户登入</h2>
      <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
        <el-form-item label="账号">
          <el-input v-model="formLabelAlign.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="formLabelAlign.region"></el-input>
        </el-form-item>
      </el-form>
      <el-row>
        <el-button type="primary" @click="login_jiekou()">登录</el-button>
        <el-button type="warning">注册</el-button>
      </el-row>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  components: {},
  data() {
    return {
      labelPosition: "top",
      formLabelAlign: {
        name: "",
        region: "",
        type: ""
      }
    };
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    login_jiekou() {
      const login = {};
      login.username = this.formLabelAlign.name;
      login.password = this.formLabelAlign.region;
      this.$http.get("/login").then(res => {
        const {
          code,
          posts: {
            data,
            meta: { msg, status }
          }
        } = res.data;
        window.console.log(res)
        if (status === 200 && login.username == data.username) {
          localStorage.setItem('token',data.token);
          this.$router.push({ name: "index" });
          this.$message.success(msg);
        } else {
          this.$router.push({ name: "Login" });
          this.$message.error("登入失败");
        }
      });
    }
  }
};
</script>
<style>
.login {
  height: 100vh;
  background-color: #ccc;
  display: flex;
  justify-content: center;
  align-items: center;
}
.login_start {
  border: 1px solid black;
  padding: 3rem;
  background-color: aliceblue;
}
</style>